/***************************************************
> Copyright (C) 2023 ==KINGYI== All rights reserved.
> File Name: queue.c
> Author:li
> Mail:joseph2009@163.com 
> Created Time: 2023年09月14日 星期四 17时43分38秒
***************************************************/

#include <stdio.h>
#include <string.h>
#include "queue.h"


struct task_queue* create_queue(void)
{
	struct task_queue *que = NULL;
	que = malloc(sizeof(struct task_queue));
	if(que == NULL)
	{
		perror("create_queue");
		return NULL;
	}
	memset(&que->task,0,sizeof(struct task));
	que->next = NULL;

	return que;
}
void push(struct task_queue *que,struct task task)
{
	struct task_queue *tail = que;

	while(tail->next != NULL)
	{
		tail = tail->next;
	}

	tail->next = malloc(sizeof(struct task_queue));
	tail = tail->next;
	tail->task = task;
	
	tail->next = NULL;
}

struct task front(struct task_queue* que)
{
	struct task_queue *head = que->next;
	return head->task;
}
void pop(struct task_queue *que)
{
	struct task_queue *p = que->next;
	que->next = p->next;
	free(p);
}
int isempty(struct task_queue* que)
{
	struct task_queue *head = que;
	if(head->next == NULL)
	{
		return 0;
	}
	
	return 1;
}

int size(struct task_queue *que)
{
	struct task_queue *tail = que;
	int count = 0;

	while(tail->next != NULL)
	{
		tail = tail->next;
		count++;
	}
	return count;
}

